//
//  UserManager.m
//  NiuBanJinGold
//
//  Created by Billy on 15/9/17.
//  Copyright (c) 2015年 zzjr. All rights reserved.
//

#import "UserManager.h"
#import "User.h"
#import "SFHFKeychainUtils.h"
#import "UserManager.h"

@implementation UserManager

@synthesize user = _user;

+ (UserManager *) sharedUserManager {
    
    static UserManager *sharedUserManager = nil;
    static dispatch_once_t predicate;
    
     dispatch_once(&predicate, ^{
         
         sharedUserManager = [[self alloc] init];
     });
    
    return sharedUserManager;
}

- (BOOL) isLogin {
     
    return self.user.user_userId !=nil;
}

- (void)logOut {

    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"user"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"gesturePasswordEnabled"];
}

- (BOOL)isAuthentication {
    
    if ([self.user.user_isRealNameAuthentication integerValue] == 1) {
        
        return YES;
    }else  {
        
        return NO;
    }
}

- (BOOL) isCardBinding {
    
    if ([self.user.user_isCardBinding integerValue] == 1) {
        
        return YES;
    }else  {
        
        return NO;
    }
}

- (BOOL) isSuccessPayment { //暂时没用
    
    if ([self.user.user_isRealNameAuthentication integerValue] == 1) {
        
        return YES;
    }else  {
        
        return NO;
    }
}

- (void) saveCurrentUser:(User *) user {
    
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user];
    [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"user"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (User *) getCurrentUser {
    
    NSData *getData =  [[NSUserDefaults standardUserDefaults] objectForKey:@"user"];
    return [NSKeyedUnarchiver unarchiveObjectWithData:getData];
}

- (User *) user {
    
    return [self getCurrentUser];
}

- (void)setUser:(User *)user {
    
    _user = user;
}

@end
